<?php

class cat_model extends CI_Model {
    public function __construct() {
        parent::__construct();
    }
    
    public function getFirstPageData() {
        $query = $this->db->query("select c.*
                                    , (select count(*) FROM gs_product p where p.CAT_ID = c.CAT_ID) as prd_count
                                    from gs_category c
                                    where sort_order is not null
                                    order by sort_order"); 
    
        return $query;
    }
    
    public function getCatNameById($cat_id){
        $query = $this->db->query('select CAT_NAME from GS_CATEGORY where CAT_ID = '.$cat_id);
        $row = $query->row(); 
        
        if($row){
            return $row->CAT_NAME;
        } else {
            return 'ไม่พบรายการ';
        }
    }
}
?>
